package com.sprite.htr.spritehtr;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

/**
 * Created by admin on 2017/6/29.
 */
public class LoginActivity extends Activity implements View.OnClickListener{
    private Button btn_login;
    private Button btn_logout;
   private String user,password;
    private EditText et_user,et_password;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        initUI();
    }

    private void initUI(){
        btn_login = (Button) findViewById(R.id.btn_login);
        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                et_user=(EditText) findViewById(R.id.et_username);
                et_password=(EditText)findViewById(R.id.et_password);
                user=et_user.getText().toString();
                password=et_password.getText().toString();
                if("admin".equals(user)&&"123".equals(password)) {
                    Intent intent = new Intent();
                    intent.setClass(getApplicationContext(), MainActivity.class);
                    startActivity(intent);
                }else if("".equals(user)||"".equals(password)){
                    Toast.makeText(getApplicationContext(), "账号或密码不能为空", Toast.LENGTH_SHORT).show();
                }else if(user.length()<5){
                    Toast.makeText(getApplicationContext(), "账号至少要求5位或以上", Toast.LENGTH_SHORT).show();
                }else if(password.length()<3){
                    Toast.makeText(getApplicationContext(), "密码至少要求3位或以上", Toast.LENGTH_SHORT).show();
                }else{
                    Toast.makeText(getApplicationContext(), "账号或密码错误", Toast.LENGTH_SHORT).show();
                }
            }
        });
        btn_logout = (Button) findViewById(R.id.btn_logout);

        btn_logout.setOnClickListener(this);
    }
    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id){
            case R.id.btn_logout:
                Toast.makeText(getApplicationContext(), "登出", Toast.LENGTH_SHORT).show();
                break;
        }
    }
}